package SocketTool;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

public class InetAddressTest {
public static void main(String[] args) throws IOException {
	InetAddress ip=InetAddress.getByName("sdw.hunnu.edu.cn");
	System.out.println("判断是否可达\t"+ip.isReachable(2000));
	System.out.println("判断地址\t"+ip.getHostAddress());
	
	InetAddress local=InetAddress.getByAddress(new byte[] {127,0,0,1});
	System.out.println(local.isReachable(5000));
	System.out.println(local.getCanonicalHostName());
	
	
	   InetAddress i = InetAddress.getLocalHost();
   System.out.println(i);                  //计算机名称和IP
   System.out.println(i.getHostName());    //名称
   System.out.println(i.getHostAddress()); //只获得IP
}
}
